package com.wgf.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DashSocpeConfig {

    @Value("${spring.ai.dashscope.api-key}")//从配置文件中注入DashScope的API密钥
    private String apiKey;

    @Bean // 创建一个DashScopeApi的Bean，用于与阿里云的DashScope API交互
    public DashScopeApi dashScopeApi()
    {
        return DashScopeApi.builder()
                .apiKey(apiKey)
                .workSpaceId("llm-lbdh7ytyo251yvr7")//左下角默认业务空间id
                .build();
    }

    @Bean // 创建ChatClient的Bean，它封装了ChatModel，用于与AI模型进行交互
    public ChatClient chatClient(ChatModel dashscopeChatModel)
    {
        return ChatClient.builder(dashscopeChatModel).build();
    }
}
